package com.huonan.component.tmp.filter;

import com.huonan.component.tmp.vo.ExtractRegularInfo;
import com.huonan.component.tmp.vo.UserLanguageTextVo;
import com.mininglamp.bia.emojiextractor.PlatformEnum;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 微博站点文本处理
 */
public class WeiboUserTextFilter extends UserTextFilter {

    //转发
    private final String FORWARD_REGULAR = "//@(.*?):";
    // 昵称
    private final String NICKNAME_REGULA = "@([^@\\s]{1,30})(?:\\s|#|$)";
    // 话题
    private final String TOPIC_REGULA = "#([^#]+)#";
    // 链接
    private final String LINK_REGULA = "\\b(?:https?://|www\\.)\\S+(?:\\\\.html|\\.htm|\\.shtml|\\.xml)?\\b";

    @Override
    public UserLanguageTextVo filter(String text) {
        ExtractRegularInfo exTractReg = ExtractRegularInfo.builder()
                .nickNameReg(NICKNAME_REGULA)
                .build();
        UserLanguageTextVo userLanguageTextVo = this.doFilter(PlatformEnum.WEIBO, text, exTractReg);
        formatTags(userLanguageTextVo);
        return userLanguageTextVo;
    }

    @Override
    public void formatTags(UserLanguageTextVo userLanguageTextVo) {
        List<String> nickNameList = userLanguageTextVo.getNickNameList();
        if (nickNameList != null && !nickNameList.isEmpty()) {
            List<String> list = nickNameList.stream()
                    .map(x -> x.trim().substring(1))
                    .collect(Collectors.toList());
            userLanguageTextVo.setNickNameList(list);
        }
    }
}
